package co.edu.unal.satacredito.rest.repositories.visa;

import java.io.Serializable;

import javax.ejb.Stateless;

import co.edu.unal.satacredito.rest.domain.visa.CreditCardTransaction;
import co.edu.unal.satacredito.rest.domain.visa.DebitCardTransaction;
import co.edu.unal.satacredito.rest.domain.visa.ValidationStatus;

/**
 * Session Bean implementation class ValidateVisa
 */
@Stateless
public class ValidateVisaImpl implements ValidateVisa, Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public boolean validateCreditCardTransaction(CreditCardTransaction creditCardTransaction) {
		
		double random = Math.random();
		if(random < 0.5){
			creditCardTransaction.setValidationStatus(ValidationStatus.VALID);
			return true;
		}else{
			creditCardTransaction.setValidationStatus(ValidationStatus.INVALID);
			return false;
		}
	}

	@Override
	public boolean validateDeditCardTransaction(DebitCardTransaction debitCardTransaction) {
		
		double random = Math.random();
		if(random < 0.5){
			debitCardTransaction.setValidationStatus(ValidationStatus.VALID);
			return true;
		}else{
			debitCardTransaction.setValidationStatus(ValidationStatus.INVALID);
			return false;
		}
	}
	
}
